// Local
#include "testmash.h"
#include "mash.h"
#include "mash_step.h"
#include "temperature.h"
#include "volume.h"
#include "duration.h"
#include "util.h"

// QtCore
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QString>

// QtXml
#include <QDomDocument>

// QtTest
#include <QTest>

// Entry point
QTEST_MAIN(testMash)

void testMash::Basics()
{
    QString Name("DaName");
    int Version = 98765;
    Temperature GrainTemp(85,Farhenheit);
    Mash zeMash(Name,Version,GrainTemp);

    QString sName("DaStepname");
    int sVersion = 338732;
    MashStepType sType = MSTTemperature;
    Temperature sTemp(62,Celsius);
    Duration sTime(120,Minute);
    MashStep *zeStep = new MashStep(sName,sVersion,sType,sTemp,sTime);

    zeMash._MashSteps.append(zeStep);
    QVERIFY(zeMash._Name==Name);
    QVERIFY(zeMash._Version==Version);
    QVERIFY(zeMash._GrainTemp==GrainTemp);
    QVERIFY(zeMash._MashSteps.size()==1);
    QVERIFY(zeMash._MashSteps[0]==zeStep);
    QVERIFY(zeMash._MashSteps[0]->_Name==sName);
    QVERIFY(zeMash._MashSteps[0]->_Version==sVersion);
    QVERIFY(zeMash._MashSteps[0]->_Type==sType);
    QVERIFY(zeMash._MashSteps[0]->_StepTemp==sTemp);
    QVERIFY(zeMash._MashSteps[0]->_StepTime==sTime);
}

void testMash::ParseXML()
{
    Q_INIT_RESOURCE(test_mash);

    // Parse XML
    QFile Input(":/Mash.xml");
    QDomDocument doc("mash");
    QVERIFY(Input.open(QIODevice::ReadOnly));
    QVERIFY(doc.setContent(&Input));

    Mash zeMash;
    QVERIFY(0==zeMash.CreateFromXMLNode(doc));
    QVERIFY(zeMash._Name=="Single Infusion, Full Body");
    QVERIFY(zeMash._Version==1);
    QVERIFY(zeMash._GrainTemp==22.222222);
    QVERIFY(zeMash._TunTemp==22.222222);
    QVERIFY(zeMash._SpargeTemp==75.555556);
    QVERIFY(ComparePrecision(zeMash._PH,5.4,0.001));
    QVERIFY(zeMash._TunWeight==1.814368);
    QVERIFY(ComparePrecision(zeMash._TunSpecificHeat,0.3));
    QVERIFY(zeMash._EquipAdjust==false);
    QVERIFY(zeMash._Notes.isEmpty());
    QVERIFY(zeMash._MashSteps.size()==2);
    QVERIFY(zeMash._MashSteps[0]->_Name=="Mash In");
    QVERIFY(zeMash._MashSteps[0]->_Version==1);
    QVERIFY(zeMash._MashSteps[0]->_Type==MSTInfusion);
    QVERIFY(zeMash._MashSteps[0]->_InfuseAmount==10.646532);
    QVERIFY(zeMash._MashSteps[0]->_StepTime==45);
    QVERIFY(zeMash._MashSteps[0]->_StepTemp==70);
    QVERIFY(zeMash._MashSteps[0]->_RampTime==2);
    QVERIFY(zeMash._MashSteps[0]->_EndTemp==70);
    QVERIFY(zeMash._MashSteps[1]->_Name=="Mash Out");
    QVERIFY(zeMash._MashSteps[1]->_Version==1);
    QVERIFY(zeMash._MashSteps[1]->_Type==MSTInfusion);
    QVERIFY(zeMash._MashSteps[1]->_InfuseAmount==6.813780);
    QVERIFY(zeMash._MashSteps[1]->_StepTime==10);
    QVERIFY(zeMash._MashSteps[1]->_StepTemp==75.555556);
    QVERIFY(zeMash._MashSteps[1]->_RampTime==2);
    QVERIFY(zeMash._MashSteps[1]->_EndTemp==75.555556);
}

void testMash::ToXML()
{

}
